<template>
  <div class="flex" style="flex: 1">
  <div style="flex:1.2;" class="flex">
    <criteria-paged :model="model" v-ref:paged   @sort="sort">
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-inline" partial>
          <!-- <card-info-modal :show.sync="$parent.$parent.cardModal_show" :cardinfo="$parent.$parent.cardInfo" v-ref:cardinfo></card-info-modal> -->
          <div class="form-group">
            <!-- <read-card @read-info="$parent.$parent.cardBtn" v-if="!$parent.$parent.noRead"></read-card> -->
          </div>
          <div class="form-group">
            <input  type="text" class="form-control" v-model="model.f_userinfo_id" placeholder='用户编号'
            condition="u.f_userinfo_id = '{}'"
            :size="model.f_userinfo_id ? model.f_userinfo_id.length : 4">
          </div>
          <div class="form-group">
            <input  type="text" class="form-control" v-model="model.f_user_name" placeholder='用户姓名'
            condition="u.f_user_name like '%{}%'"
            :size="model.f_user_name ? model.f_user_name.length * 2 : 4">
          </div>
          <div class="form-group">
            <input  type="text" class="form-control" v-model="model.f_address" placeholder='用户地址'
            condition="u.f_address like '%{}%'"
            :size="model.f_address ? model.f_address.length * 2 : 4">
          </div>
          <div class="form-group">
            <input  type="text" class="form-control" v-model="model.f_user_id" placeholder='表编号'
            condition="u.f_user_id = '{}'"
            :size="model.f_user_id ? model.f_user_id.length : 3">
          </div>
          <div class="form-group">
              <input  type="text" class="form-control" v-model="model.f_meternumber" placeholder='表号'
              condition="f_meternumber = '{}'"
              :size="model.f_meternumber ? model.f_meternumber.length : 2">
          </div>
          <div class="form-group">
            <v-select id="f_meter_brand"
            v-model="model.f_meter_brand"
            placeholder='气表品牌'
            :value.sync="model.f_meter_brand"
            :options='$parent.$parent.meterbrand'
            condition="u.f_meter_brand = '{}'"
            close-on-select ></v-select>
          </div>
          <div class="form-group" >
            <v-select :value.sync="model.f_filiale" v-model='model.f_filiale'
            :options='$parent.$parent.filiales' placeholder='分公司'
            close-on-select
            condition="u.f_filiale = '{}'"></v-select>
          </div>

          <div class="form-group">
            <v-select :value.sync="model.f_outlets" v-model='model.f_outlets'
                :options='$parent.$parent.outlets' placeholder='营业网点'
                close-on-select
                condition="u.f_outlets = '{}'"></v-select>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="search(), $parent.$parent.clean()" v-el:cx>查询</button>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
             <th>序号</th>
             <th v-if="$parent.$parent.$parent.bulkType === '抄表员变更'">抄表员</th>
             <th>
                 <data-order field="f_userinfo_id" name="用户编号" :order.sync="$parent.$parent.$parent.orderFields.f_userinfo_id"></data-order>
             </th>
			       <th>用户基本信息</th>
             <th>表具信息</th>
             <th style="white-space: nowrap;">分类信息</th>
              <th>操作</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td v-if="$parent.$parent.$parent.bulkType === '抄表员变更'">{{row.f_inputtor}}</td>
          <td>{{row.f_userinfo_id}}</td>
          <td>{{row.f_user_name}}&nbsp;&nbsp;{{row.f_user_phone}}&nbsp;&nbsp;{{row.f_address}}</td>
          <td>{{row.f_user_id}}&nbsp;&nbsp;{{row.f_gasproperties}}&nbsp;&nbsp;{{row.f_meter_brand}}
            &nbsp;&nbsp;{{row.f_meter_style}}&nbsp;&nbsp;{{row.f_price_type}}</td>
          <td style="text-align: center;">{{row.f_meter_type}}&nbsp;&nbsp;({{row.f_states}})

          </td>
            <td style="text-align: center;">
               <dropdown>
                <button type="button" data-toggle="dropdown" style="border: 0px;background: none;">
                  <span class="glyphicon glyphicon-th-list" style="position: inherit;"></span>
                </button>
                <ul slot="dropdown-menu" class="dropdown-menu dropdown-menu-right">
                  <li v-if="row.f_meter_type ==='物联网表'">
                    <a href="#" @click.stop="$parent.$parent.$parent.operate(row)"></span>补费扣费</a>
                  </li>
                </ul>
              </dropdown>
            </td>
        </template>
      </data-grid>
  </criteria-paged>
  <fillandcut-detail v-if="show" :row="data" style="margin-top: 20px;border: 1px solid #EEF3F6;"></fillandcut-detail>
  </div>
</template>

<script>
/**
*用户档案查询列表以及添加操作组件
*/
import { PagedList } from 'vue-client'
import AppData from '../../stores/AppData'
import * as Util from '../Util'
import cardlisten from '../../plugins/revenueService/CardListen'

export default {
  title: '补费扣费',
  data () {
    return {
      model: new PagedList('rs/sql/singleTable_User', 50,
       {orderitem: '"' + this.orderitem + ' DESC"'}),
      data: '',
      asideTitle: '用户操作',
      rows: null,
      cardInfo: '',
      cardModal_show: false,
      bulkType: null, // 批量操作标识
      operCard: cardlisten,
      contract: [{label: '全部', value: ''},
      {label: '有', value: 'not null'},
      {label: '无', value: 'null'}],
      orderFields: {
        f_userinfo_id: 'no'
      },
      filiale: '',
      outlet: '',
      filialeName: [],
      show: false,
      outletsname: [],
      filialetype: ''
    }
  },
  props: {
    btns: {
      type: Array,
      default: function () {
        return []
      }
    },
    orderitem: {
      type: String,
      default: 'f_userinfo_id'
    },
    excelurl: {
      type: String
    },
    queryGroup: {
      type: Array,
      default: function () {
        return []
      }
    },
    defbtn: {
      type: String
    },
    opeHeight: {
      default: 400
    },
    componentName: {
      type: String
    },
    noRead: {
      type: Boolean,
      default: false
    },
    noBatch: {
      type: Boolean,
      default: false
    },
    row: {}
  },
  ready () {
    this.search()
  },
  methods: {
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    reset () {
      this.$refs.paged.$refs.cri.model = {}
      this.model.rows = ''
    },
    operate (row) {
      this.show = true
      this.data = row
    },
    clean () {
      this.show = false
    },
    bulkOperations (type, name) {
      this.$refs.paged.$refs.grid.select(null)
      this.bulkType = type
      this.$dispatch('bulk-oper', type, name, {condition: this.model.condition, count: this.model.count})
    },
    // 判断是不是卡表
    isCard (str) {
      return str.includes('卡表')
    },
    refreshRow (row) {
      this.model.rows = [row]
      // this.$refs.paged.$refs.grid.select(this.model.rows[0])
    },
    selfSearch (args) {
      if (!Util.f.parent.parent.name.includes('统一资源管理')) {
        args.condition = `${args.condition} and u.f_filiale = '${Util.f.f_fengongsi}'`
      }
      if (this.defbtn === '发卡售气') {
        args.condition = `${args.condition} and f_whether_hairpin = '未发' and f_meter_classify like '%卡表%'`
      }
      console.log('搜索条件，，，，', args.condition)
      this.model.search(args.condition, args.model)
    },
    // 判断当前登陆人是不是子公司的人员
    isHead () {
      return Util.f.parent.parent.name.includes('统一资源管理')
    },
    sort (field, rule) {
      // 将所有排序方式设为不排序，实现相互排斥
      for (let key in this.orderFields) {
        if (key === field) {
          this.orderFields[key] = rule
        } else {
          this.orderFields[key] = 'no'
        }
      }
      // 如果新规则不排序，还原为默认排序
      if (rule === 'no') {
        this.model.paramSource.orderitem = `'${this.orderitem}'`
      } else {
        this.model.paramSource.orderitem = `'${field} ${rule}'`
      }

      this.search()
    }
    // 单条更新,业务逻辑成功后，单条刷新
    // singleRefresh (data) {
    //   let index = this.model.rows.findIndex((row, index, arr) => {
    //     return  row.f_user_id === data.f_user_id
    //   })
    //   this.$resetpost('rs/sql/singleTable_User', {data: {orderitem: this.orderitem, condition: `n.f_userinfo_id=${data.f_user_id}`}}).then((res) => {
    //     this.model.rows[index] = res.data[0]
    //   })
    // }
  },
  watch: {
    'cancel' () {
      console.log('22222222222')
      this.clean()
    }
  },
  computed: {
    hairpins () {
      return [{label: '全部', value: ''}, ...AppData.getParam('卡状态')]
    },
    tableStates () {
      return [{label: '全部', value: ''}, ...AppData.getParam('表状态')]
    },
    userStates () {
      return [{label: '全部', value: ''}, ...AppData.getParam('用户状态')]
    },
    whetherPay () {
      return [
        {label: '全部', value: ''},
        {label: '已缴费', value: '是'},
        {label: '未缴费', value: '否'}
      ]
    },
    filiales () {
      let rs = []
      for (let i = 0; i < Util.f.f_allfiliale.length; i++) {
        rs.push({label: Util.f.f_allfiliale[i].label, value: Util.f.f_allfiliale[i].label})
      }
      return [{label: '全部', value: ''}, ...rs]
    },
    outlets () {
      let rs = []
      console.log('档案营业网点。。。', this.$refs.paged.$refs.cri.model.f_filiale)
      if (this.$refs.paged.$refs.cri.model.f_filiale.length > 0) {
        for (let i = 0; i < Util.f.f_allfiliale.length; i++) {
          if (Util.f.f_allfiliale[i].label === this.$refs.paged.$refs.cri.model.f_filiale[0]) {
            rs = Util.f.f_allfiliale[i].value
          }
        }
      }
      console.log('获取档案营业网点。。。。', rs)
      return [{label: '全部', value: ''}, ...rs]
    },
    meterbrand () {
      let arr = []
      AppData.getGasbrand().forEach((item) => {
        let temp = {}
        temp.label = item.label
        temp.value = item.value.f_meter_brand
        arr.push(temp)
      })
      return [{label: '全部', value: ''}, ...arr]
    },
    firestates () {
      return [
        {label: '全部', value: ''},
        {label: '点火', value: '1'},
        {label: '未点火', value: '0'}
      ]
    },
    jurisdiction () {
      return Util.r
    }
  }
}
</script>
<style media="screen">
  .divtext {
    min-width: 50px;
    max-width: 200px;
    border: 1px solid green;
    display: inline-block;
  }
</style>
